package logic.SysOrganizationalUnit

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysOrganizationalUnit
import cn.ibizlab.core.ad.domain.SysOrganizationalUnit
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  获取OU清单信息(指定单位/我的)_备份
 */
class ItemsBk {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    def _filter = new EntityBase()
    //list
    def _list = new SysOrganizationalUnit()
    def _orgid = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //连接名称
        if(true) {
            prepareparam1()
        }
    }

    //准备参数
    def prepareparam1() {
        _filter.set("size", "10000")
        _filter.set("n_filter_like", _default.get("filter"))

        //orgid not null
        if(((RuleUtils.test(_default.get('id'), 'ISNOTNULL', 'null')))) {
            delogic1()
        }
        //orgid null
        else if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')))) {
            dedataquery2()
        }
    }

    //换取orgid
    def delogic1() {
        logic.SysOrganization.findOrganizationId logic = new logic.SysOrganization.findOrganizationId()
        logic.execute(_default)

        //orgid not null
        if(((RuleUtils.test(_orgid, 'ISNOTNULL', 'null')))) {
            prepareparam2()
        }
        //orgid null
        else if(((RuleUtils.test(_orgid, 'ISNULL', 'null')))) {
            dedataquery2()
        }
    }

    //准备参数
    def prepareparam2() {
        _filter.set("n_organization_id_eq", _orgid.get(""))

        if(true) {
            dedataquery1()
        }
    }

    //查询我的ou
    def dedataquery2() {
        //DEDataQuery 暂未实现
        if(true) {
            end1()
        }
    }

    //查询单位ou
    def dedataquery1() {
        //DEDataQuery 暂未实现
        if(true) {
            end1()
        }
    }

    //结束
    def end1() {
        _return = _list

    }

}
